package com.cryptoneedle.garden.service.crud.garden.source;


import com.cryptoneedle.garden.entity.source.constraint.*;
import com.cryptoneedle.garden.entity.source.enhance.SourceDimension;
import com.cryptoneedle.garden.entity.source.metadata.*;
import com.cryptoneedle.garden.repository.source.constraint.*;
import com.cryptoneedle.garden.repository.source.enhance.SourceDimensionRepository;
import com.cryptoneedle.garden.repository.source.metadata.*;
import com.cryptoneedle.garden.service.garden.source.metadata.CatalogService;
import com.cryptoneedle.garden.vo.CatalogSaveVo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>description:  </p>
 *
 * @author CryptoNeedle
 * @date 2025-10-23
 */
@Slf4j
@Service
@Transactional
public class AddSourceService {

    @Autowired
    private FoundSourceService select;
    @Autowired
    private AddSourceService add;
    @Autowired
    private PatchSourceService patch;
    @Autowired
    private SaveSourceService save;
    @Autowired
    private DeleteSourceService delete;

    @Resource
    private SourceServerRepository sourceServerRepository;
    @Resource
    private SourceCatalogRepository sourceCatalogRepository;
    @Resource
    private SourceDatabaseRepository sourceDatabaseRepository;
    @Resource
    private SourceTableRepository sourceTableRepository;
    @Resource
    private SourceColumnRepository sourceColumnRepository;

    @Resource
    private SourceConstraintCheckRepository sourceConstraintCheckRepository;
    @Resource
    private SourceConstraintForeignRepository sourceConstraintForeignRepository;
    @Resource
    private SourceConstraintPrimaryRepository sourceConstraintPrimaryRepository;
    @Resource
    private SourceConstraintUniqueRepository sourceConstraintUniqueRepository;
    @Resource
    private SourceIndexUniqueRepository sourceIndexUniqueRepository;

    @Resource
    private SourceDimensionRepository sourceDimensionRepository;

    @Resource
    private CatalogService catalogService;

    /**
     * SourceServerRepository
     */
    public void add(SourceServer entity) {
        sourceServerRepository.save(entity);
    }

    public void servers(List<SourceServer> list) {
        sourceServerRepository.saveAll(list);
    }

    /**
     * SourceCatalogRepository
     */
    public void add(SourceCatalog entity) {
        sourceCatalogRepository.save(entity);
    }

    public void catalogs(List<SourceCatalog> list) {
        sourceCatalogRepository.saveAll(list);
    }

    public void add(CatalogSaveVo entity) {
        catalogService.addVo(entity);
    }

    /**
     * SourceDatabaseRepository
     */
    public void add(SourceDatabase entity) {
        sourceDatabaseRepository.save(entity);
    }

    public void databases(List<SourceDatabase> list) {
        sourceDatabaseRepository.saveAll(list);
    }

    /**
     * SourceTableRepository
     */
    public void add(SourceTable entity) {
        sourceTableRepository.save(entity);
    }

    public void tables(List<SourceTable> list) {
        sourceTableRepository.saveAll(list);
    }

    /**
     * SourceColumnRepository
     */
    public void add(SourceColumn entity) {
        sourceColumnRepository.save(entity);
    }

    public void columns(List<SourceColumn> list) {
        sourceColumnRepository.saveAll(list);
    }

    /**
     * SourceConstraintCheckRepository
     */
    public void add(SourceConstraintCheck entity) {
        sourceConstraintCheckRepository.save(entity);
    }

    public void constraintChecks(List<SourceConstraintCheck> list) {
        sourceConstraintCheckRepository.saveAll(list);
    }

    /**
     * SourceConstraintForeignRepository
     */
    public void add(SourceConstraintForeign entity) {
        sourceConstraintForeignRepository.save(entity);
    }

    public void constraintForeigns(List<SourceConstraintForeign> list) {
        sourceConstraintForeignRepository.saveAll(list);
    }

    /**
     * SourceConstraintPrimaryRepository
     */
    public void add(SourceConstraintPrimary entity) {
        sourceConstraintPrimaryRepository.save(entity);
    }

    public void constraintPrimarys(List<SourceConstraintPrimary> list) {
        sourceConstraintPrimaryRepository.saveAll(list);
    }

    /**
     * SourceConstraintUniqueRepository
     */
    public void add(SourceConstraintUnique entity) {
        sourceConstraintUniqueRepository.save(entity);
    }

    public void constraintUniques(List<SourceConstraintUnique> list) {
        sourceConstraintUniqueRepository.saveAll(list);
    }

    /**
     * SourceIndexUniqueRepository
     */
    public void add(SourceIndexUnique entity) {
        sourceIndexUniqueRepository.save(entity);
    }

    public void indexUniques(List<SourceIndexUnique> list) {
        sourceIndexUniqueRepository.saveAll(list);
    }

    /**
     * SourceDimensionRepository
     */
    public void add(SourceDimension entity) {
        sourceDimensionRepository.save(entity);
    }

    public void dimensions(List<SourceDimension> list) {
        sourceDimensionRepository.saveAll(list);
    }
}